package cn.gzsf.coolshark.mapper;

import cn.gzsf.coolshark.entity.Product;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Mapper
public interface ProductMapper {
    @Insert("insert into product (title,price,old_price,sale_count,num,url,category_id,view_count) " +
            "values (#{title},#{price},#{oldPrice},#{saleCount},#{num},#{url},#{categoryId},#{viewCount})")
    int insert(Product product);
    @Select("select * from product ")
    List<Product> select();
    @Select("select url from product where id=#{id}")
    String selectUrlById(int id);
    @Delete("delete from product where id=#{id}")
    void deleteById(int id);
    @Select("select * from product where id=#{id}")
    Product selectById(int id);
    @Update("update product set title=#{title},price=#{price},old_price=#{oldPrice}," +
            "sale_count=#{saleCount},num=#{num},url=#{url},category_id=#{categoryId} where id=#{id}")
    void update(Product product);
    @Select("select id,title,sale_count from product order by sale_count desc limit 0,6")
    List<Product> selectTop();
    @Select("select id,title,price,old_price,sale_count,url from product")
    List<Product> selectIndex();
    @Select("select id,title,price,old_price,sale_count,url,created,view_count from product where id=#{id}")
    Product selectDetailById(int id);
    @Select("select  id,title,price,old_price,sale_count,url from product where category_id=#{id}")
    List<Product> selectByCategoryId(int id);
}
